<style type="text/css" title="currentStyle">
	@import "../media/css/demo_page.css";
	@import "../media/css/demo_table_jui.css";
	@import "../examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css";
	@import "media/css/TableTools_JUI.css";
</style>
<script type="text/javascript" charset="utf-8" src="../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready( function () {
		$('#example').dataTable( {
			"bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"sDom": 'Tlfrtip',
			"oTableTools": {
				"aButtons": [
					"copy", "csv", "xls", "pdf", "print",
					{
						"sExtends":    "collection",
						"sButtonText": "Save",
						"aButtons":    [ "csv", "xls", "pdf" ]
					}
				]
			}
		} );
	} );
</script>
<?php
function GetRemoteLastModified( $uri )
{
    // default
    $unixtime = 0;
   
    $fp = @fopen( $uri, "r" );
    if( !$fp ) {return;}
   
    $MetaData = stream_get_meta_data( $fp );
       
    foreach( $MetaData['wrapper_data'] as $response )
    {
        // case: redirection
        if( substr( strtolower($response), 0, 10 ) == 'location: ' )
        {
            $newUri = substr( $response, 10 );
            fclose( $fp );
            return GetRemoteLastModified( $newUri );
        }
        // case: last-modified
        elseif( substr( strtolower($response), 0, 15 ) == 'last-modified: ' )
        {
            $unixtime = date('d-m-Y h:i:s A',strtotime( substr($response, 15) ));
            break;
        }
    }
    fclose( $fp );
    return $unixtime;
}
//print (strtotime('17:59:15') - strtotime('15:59:05')) - 3600; //prints 3600 (1 hour in seconds)	

/*
function getMyTimeDiff($t1,$t2)
{
$a1 = explode(":",$t1);
$a2 = explode(":",$t2);
$time1 = (($a1[0]*60*60)+($a1[1]*60)+($a1[2]));
$time2 = (($a2[0]*60*60)+($a2[1]*60)+($a2[2]));
$diff = abs($time1-$time2);
$hours = floor($diff/(60*60));
$mins = floor(($diff-($hours*60*60))/(60));
$secs = floor(($diff-(($hours*60*60)+($mins*60))));
$result = $hours.":".$mins.":".$secs;
return $diff;
}
$mytime1 = "14:00:20";
$mytime2 = "13:00:00";
echo $cool = getMyTimeDiff($mytime1,$mytime2);*/

	$selUsers="SELECT * FROM tb_clientinfo";				
	$q = $selUsers;
	$r = mysql_query($q);

	$selUsers=$selUsers." ORDER BY ci_clientName ";
	$rs_getUserDetails = mysql_query($selUsers);
?>
<div id="formDiv">
<form name="view_school_vehicle" id="view_school_vehicle" action="" method="post" autocomplete="off">
<table class="gridform_final">
<tr><th colspan="5">Device Status</th></tr>
  <tr>
  <td width="15%" align="right"><span class="form_text">Select Client&nbsp;</span></td>
    <td width="15%" align="right">
    <select name="client_id" id="client_id" onchange="document.view_school_vehicle.submit();">
    	<option value="0">All Client</option>
        <?php
        while($fetch_getUserDetails = @mysql_fetch_assoc($rs_getUserDetails))
        {
            if($fetch_getUserDetails[ci_id] == $_POST[client_id])
                $selected = "selected";
            else
                $selected = "";
        ?>
            <option value="<?php echo $fetch_getUserDetails[ci_id]; ?>" <?php echo $selected; ?>>
                <?php echo $fetch_getUserDetails[ci_clientName]." - ".$fetch_getUserDetails[ci_id]; ?>
            </option>
        <?php
        }
        ?>
       </select>
       </td>
       <td width="15%" align="right"><span class="form_text">Device Id&nbsp;/&nbsp;Name&nbsp;/&nbsp;IMEI&nbsp;/&nbsp;Mobile</span></td>
    	<td width="15%" align="right">
        <input type="text" name="search_vehicle_no" id="search_vehicle_no" class="" value="<?php echo $_POST[search_vehicle_no]; ?>" />
        </td>
        <td>
        <input type="submit" name="search_vehicle_no_submit" id="search_vehicle_no_submit" value="Go" class="save_btn" />
        <input type="button" name="search_vehicle_no_cancel" id="search_vehicle_no_cancel" value="Cancel" class="save_btn" onclick="location.href='?ch=devStatus'" />
    </td>
  </tr>
  </table>
</form>
</div>
<?php
if(isset($_POST[client_id]) && $_POST[client_id]!='')
{
?>
<table cellpadding="0" cellspacing="0" border="0" class="gridform_final" id="example">      
  <thead>
<tr>
    <th width="193">Client Name</th>
    <th width="115">Device&nbsp;ID</th>
    <th width="128">Device&nbsp;Name</th>
    <th width="152">Last data received Date & Time</th>
    <th width="152" style="border:0px;">File Modified Date & Time</th>
</tr>
</thead>
<tbody>
<?php
//print_r($_POST);
if($_POST[search_vehicle_no]!='')
{
    $vehi_search_qry = " AND (di_deviceName='".trim($_POST[search_vehicle_no])."' OR di_deviceId='".trim($_POST[search_vehicle_no])."' OR di_imeiId='".trim($_POST[search_vehicle_no])."' OR di_mobileNo='".trim($_POST[search_vehicle_no])."')";
}
if($_POST[client_id] > 0)
{
	$selClients="SELECT ci_id,ci_clientName,di_deviceName,di_deviceId,di_imeiId FROM tb_clientinfo,tb_deviceinfo WHERE ci_id=di_clientId AND di_clientId=".$_POST[client_id]." ".$vehi_search_qry;
}
else
{
	$selClients="SELECT ci_id,ci_clientName,di_deviceName,di_deviceId,di_imeiId FROM tb_clientinfo,tb_deviceinfo WHERE ci_id=di_clientId ".$vehi_search_qry;
}
$rs_selClients_tot = mysql_query($selClients);
$tot = @mysql_num_rows($rs_selClients_tot);
$selClients.=" LIMIT ".$s.",".$n;
$rs_selClients = mysql_query($selClients);
while($fetch_getDetails=@mysql_fetch_assoc($rs_selClients))
{
?>
  <tr class=<?php if(($i%2)==0) echo "even"; else echo "odd";?>>
    <td><?php echo $fetch_getDetails[ci_clientName]; ?></td>
    <td><?php echo $fetch_getDetails[di_deviceId]; ?></td>
    <td><?php echo $fetch_getDetails[di_deviceName]; ?></td>
    <td><?php 
			$sdate = date("d-m-Y",strtotime($fetDevice[di_createDate]));
			$edate = date("d-m-Y");			
			$z = GetDays($sdate, $edate);
			$count = 1;
			
			$getLiveData = "SELECT * FROM tb_livegps_info WHERE tli_imei = '".$fetch_getDetails[di_imeiId]."'";
			$exeLiveData = $db->query($getLiveData);
			if($db->affected_rows > 0)
			{
				$fetLiveData = $db->fetch_array($exeLiveData);
				$data111_arr1 = explode('#',$fetLiveData[tli_parameter]);
				$data111_arr1 = explode(',',$data111_arr1[count($data111_arr1)-2]);
				$gpsTime = $data111_arr1[8]." ".$data111_arr1[9];
				echo $gpsTime."</td><td>";
				$path1 = DATAPATH.$fetLiveData[tli_date]."/".$fetch_getDetails[di_imeiId].".txt";
				echo GetRemoteLastModified($path1);
				$count++;
			}
        ?>
    </td>
  </tr>
  <?php 
    $i++;
}				
?>
	<tfoot>
	<tr>
    	<td colspan="3" style="text-align:right;">Total - <?php echo $tot;?></td>
		<td colspan="2" style="text-align:right;">Running - <?php echo $count;?></td>
    </tr>
	</tfoot>
</tbody>
</table>
<?php } ?>

<form name="formpagination" id="formpagination" action="" method="post">
	<input type="hidden" name="pn" id="pn" value="<?php if(isset($_POST[pn])) echo $_POST[pn]; else echo '1'; ?>" />
	<input type="hidden" name="nr" id="nr" value="<?php echo $_POST[nr]?>" />
	<input type="hidden" name="search_vehicle_no" id="search_vehicle_no" value="<?php echo $_POST[search_vehicle_no]; ?>">
	<input type="hidden" name="client_id" id="client_id" value="<?php echo $_POST[client_id]; ?>">
	<input type="hidden" name="pageSelect" value="" />
</form>